package com.java1412.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 支付宝的配置
 *
 * @author java1412
 * @since 2023-06-26 16:04:48
 */
@Data
@Component
@ConfigurationProperties(prefix = "alipay")
public class AlipayConfig {
    private String appId;
    private String appPrivateKey;
    private String alipayPublicKey;
    private String notifyUrl;

    @PostConstruct // 完成初始化，在构造方法之后执行
    public void init() {
//        System.out.println(this.appId);
//        System.out.println(this.appPrivateKey);
//        System.out.println(this.alipayPublicKey);
        // 定义阿里支付的配置对象
        Config config = new Config();
        // 指明协议
        config.protocol = "https";
        // 指明网关
        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
        // 指明签名方式
        config.signType = "RSA2";
        // 指明应用编号，应用私钥，支付宝公钥回调地址
        config.appId = this.appId;
        config.merchantPrivateKey = this.appPrivateKey;
        config.alipayPublicKey = this.alipayPublicKey;
        config.notifyUrl = this.notifyUrl;
        // 向支付工厂中注册
        Factory.setOptions(config);
        System.out.println("============阿里支付sdk配置成功==============");
    }
}
